class StringTool {

  static isEmpty(String str){
    bool isEmpty = false;
    if(str==null||str.isEmpty||str=='null'){
      isEmpty = true;
    }
    return isEmpty;
  }

  static String getDWstr(int type){

    if(type!=null&&type==1){
      return '/斤';
    }
    return '/吨';
  }

  //替换字符中的空格和换行标签
  static String textFlutterString(String _text) {
    if (_text != null) {
      _text = _text.replaceAll(RegExp(r'<br\/?>'), "\r\n");
      _text = _text.replaceAll(RegExp(r'&nbsp;'), " ");
    } else {
      _text = '';
    }
    return _text;
  }

  //驼峰转化为下划线
  static String camel2under(String val) {
    if (val == null) {
      return '';
    }
    String separator = "_";
    val = val.replaceAllMapped(RegExp(r"([a-z])([A-Z])"), (Match m) {
      return "${m[1]! + separator + m[2]!}";
    }).toLowerCase();
    return val;
  }

  //下划线转化为驼峰
  static String under2camel(String val) {
    if (val == null) {
      return '';
    }
    String underString = "";
    val = val.toLowerCase().replaceAll(new RegExp(r'_'), " ");
    List<String> sarr = val.split(" ");
    for (int i = 0; i < sarr.length; i++) {
      String w;
      if (i > 0) {
        w = sarr[i].substring(0, 1).toUpperCase() + sarr[i].substring(1);
      } else {
        w = sarr[i];
      }

      underString += w;
    }
    return underString;
  }

  //移除url的域名前缀
  static String removeURLPrefix(String val){
    if(val == null) {
      return '';
    }
    val = val.replaceAll(new RegExp(r'^((http:\/\/)|(https:\/\/))?([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}'), "");
    return val;
  }

  static String getTaskScreen(List list) {
    String str = '';
    list.forEach((f) {
      if (str == '') {
        str = "$f";
      } else {
        str = "$str" "," "$f";
      }
    });

    return str;
  }

  //话题分割
  static List<String> getTopics(String str) {
    List<String> res = [];
    if(str==null||str.length==0){
      return res;
    }
    RegExp regExp = RegExp(r'#[^#]+#');
    for (var match in regExp.allMatches(str)) {
      res.add(match.group(0)!);
    }
    return res;
  }

  //话题转a标签
  static String getTopicLink(String str) {
    String res;
    if(str==null||str.length==0){
      return '';
    }
    res =  str.replaceAllMapped(RegExp(r'#[^#]+#'),//转换之后的内容
            (Match m) => "<a href=topic://" + m.group(0)! + ">"+ m.group(0)!+"</a>");
    return res;
  }

}